import matplotlib.pyplot as plt
import numpy as np

# 读取数据
with open('execution_times.txt', 'r') as file:
    lines = file.readlines()

# 解析数据
results = {}
for line in lines:
    exe, arg, time_val = line.split()  # 将每行数据分割成可执行文件、参数和时间
    time_val = float(time_val)  # 将时间值转换为浮点数
    if exe not in results:
        results[exe] = {}
    if int(arg) not in results[exe]:
        results[exe][int(arg)] = []
    results[exe][int(arg)].append(time_val)

# 计算中位数和标准差
medians = {}
errors = {}
for exe in results:
    medians[exe] = []
    errors[exe] = []
    for arg in results[exe]:
        medians[exe].append(np.median(results[exe][arg]))
        errors[exe].append(np.std(results[exe][arg]))

# 绘图
plt.figure(figsize=(10, 6))
for exe in results:
    args = list(results[exe].keys())
    plt.errorbar(args, medians[exe], yerr=errors[exe], capsize=5, label=exe)

plt.xlabel('Argument Value')
plt.ylabel('Time (s)')
plt.title('Execution Time Comparison')
plt.xticks(args)
plt.legend()
plt.grid(True)
plt.show()
